package net.wangds.procengine;

import net.wangds.procengine.flow.FlowEngine;
import net.wangds.procengine.flow.define.node.FlowNode;
import net.wangds.procengine.flow.instance.FlowInstance;
import net.wangds.procengine.flow.instance.actor.AnonymousActor;
import net.wangds.procengine.flow.instance.context.HashTableContext;
import org.junit.Test;

/**
 * .
 * <p></p>
 *
 * @author 王东石 2020/9/8 10:55.
 */
public class FlowTestCase {


    @Test
    @SuppressWarnings("unchecked")
    public void test() {

        defined();
        HashTableContext ctx = new HashTableContext();
        //FlowEngine.start(ctx, new AnonymousActor(), "test");
        //FlowEngine.run(ctx, new AnonymousActor(), "test");

        TestFlow flow = new TestFlow();
        AnonymousActor a = new AnonymousActor();
        flow.createFlowInstance(a, flow).ifPresent(inst->
                flow.getFlowNodes().stream().findFirst().ifPresent(firstNode->
                        FlowEngine.run(ctx, a, (FlowInstance)inst, (FlowNode)firstNode)
                )
        );

    }

    private void defined() {
        FlowEngine.registorFlowOperator(new TestFlow());
    }


}
